const express = require('express')
const Mock = require('mockjs')
const app = express()
const port = 3000

app.get('/', (req, res) => {
  res.send('Hello World!')
})

app.use(function (req, res, next) {
  res.header('Access-Control-Allow-Origin', '*')
  res.header('Access-Control-Allow-Methods', 'PUT, GET, POST, DELETE, OPTIONS')
  res.header('Access-Control-Allow-Headers', ['X-Requested-With', 'Content-Type', 'token', 'Authorization', 'X-CSRF-TOKEN', 'X-Requested-With'])
  next()
})

app.use('/home/list', function (req, res) {
  res.json(Mock.mock({
    status: 200,
    'dataSource|2-10': [{
      'key|+1': 1,
      'mockTitle|1': ['肆无忌惮'],
      'mockContent|1': ['角色精湛主题略荒诞', '理由太短 是让人不安', '疑信参半 却无比期盼', '你的惯犯 圆满', '别让纠缠 显得 孤单'],
      'mockAction|1': ['下载', '试听', '喜欢']
    }]
  }))
})

app.listen(port, () => {
  console.log('监听端口 3000')
})
